package com.example.sneakerappforme1105.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class ImageUtil {

    public static String saveImageToLocal(byte[] imageData, String fileName, String directoryPath) throws IOException {
        // 确保目录存在
        File dir = new File(directoryPath,"goodsImage2");
        if (!dir.exists()) {
            dir.mkdirs();
        }
        // 保存图片文件
        File imageFile = new File(dir, fileName);
        try (FileOutputStream fos = new FileOutputStream(imageFile)) {
            fos.write(imageData);
            fos.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return imageFile.getAbsolutePath();
    }

}
